package com.jyw.business.de.domain.vo.web;

import com.google.common.collect.Lists;
import com.jyw.business.de.domain.DeDemandAllocationConfig;
import com.jyw.common.core.domain.entity.SysDictData;
import com.jyw.system.utils.UserUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.ObjectUtils;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@ApiModel("需求类型责任人配置")
@Data
@NoArgsConstructor
public class DemandTypeAllocationUser {

    @ApiModelProperty("类型标签")
    private String dictLabel;

    @ApiModelProperty("类型值")
    private String dictValue;

    @ApiModelProperty("需求负责人")
    private List<Long> users;

    @ApiModelProperty("需求负责人名称")
    private String usersName;

    public DemandTypeAllocationUser(SysDictData data, List<DeDemandAllocationConfig> allocationConfigList) {
        setDictLabel(data.getDictLabel());
        setDictValue(data.getDictValue());
        DeDemandAllocationConfig allocationConfig = allocationConfigList.stream().filter(config -> data.getDictValue().equals(config.getDictValue())).findFirst().orElse(null);
        if(!ObjectUtils.isEmpty(allocationConfig)){
            setUsers(Arrays.asList(allocationConfig.getAllocationUser().split(",")).stream().map(user->Long.valueOf(user)).collect(Collectors.toList()));
            setUsersName(UserUtils.userIdToName(allocationConfig.getAllocationUser()));
        }else{
            setUsers(Lists.newArrayList());
        }
    }
}
